<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('按钮状态新增及修改')" />
    <style type="text/css">
        .layui-input, .layui-textarea{width:calc(100% - 100px);}
        .layui-form-label{width:180px}
        .layui-form-select dl{margin-left:80px;min-width: calc(100% - 100px);}
        .layui-edge{margin-right:28px;}
    </style>
</head>
<body>
<form class="layui-form" id="form-button-add" style="margin: 16px 84px 16px 25px;">
	<input type="hidden" id="guid" name="guid"  th:value="${buttonState?.guid}">
    <div class="layui-form-item">
        <label class="layui-form-label">按钮名称：</label>
        <div class="layui-input-block">
            <input type="text" name="butName" id="butName" th:value="${buttonState?.butName}" autocomplete="off" placeholder="tp_add" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">按钮说明：</label>
        <div class="layui-input-block">
            <input type="text" name="butCaption" id="butCaption" th:value="${buttonState?.butCaption}" autocomplete="off" placeholder="新增单据" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">按钮状态：</label>   
        <div class="layui-input-block">
        	<select name="butState" id="butState">
	             <option value="enable" th:selected="'enable' eq ${buttonState?.butState}">启用</option>
				 <option value="disable" th:selected="'disable' eq ${buttonState?.butState}">禁用</option>
	             <option value="hidden" th:selected="'hidden' eq ${buttonState?.butState}">隐藏</option>
	             <option value="hiddenexcept" th:selected="'hiddenexcept' eq ${buttonState?.butState}">指定启用</option>
	      	</select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">功能唯一标识：</label>
        <div class="layui-input-block">
            <input type="text" name="moduleTable" id="moduleTable" th:value="${buttonState?.moduleTable}" autocomplete="off" placeholder="请选择" class="layui-input">
            <i class="layui-icon layui-icon-more" style="position: absolute;right: 35px;top: 9px;" onclick="getmt('moduleTable')"></i>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">(权限)功能唯一标识：</label>
        <div class="layui-input-block">
            <input type="text" name="moduleTable2" id="moduleTable2" th:value="${buttonState?.moduleTable2}" autocomplete="off" placeholder="请选择" class="layui-input">
            <i class="layui-icon layui-icon-more" style="position: absolute;right: 35px;top: 9px;" onclick="getmt('moduleTable2')"></i>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">最低用户级别：</label>
        <div class="layui-input-block">
            <input type="text" name="minUserLevel" id="minUserLevel" th:value="${buttonState?.minUserLevel}" autocomplete="off" placeholder="请输入" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">始终启用用户级别：</label>
        <div class="layui-input-block">
            <input type="text" name="alwaysEnableUserLevel" id="alwaysEnableUserLevel" th:value="${buttonState?.alwaysEnableUserLevel}" autocomplete="off" placeholder="请输入" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">指定用户：</label>
        <div class="layui-input-block">
        	<input type="text" name="exceptForUser" id="exceptForUser" th:value="${buttonState?.exceptForUser}" autocomplete="off" placeholder="请选择" class="layui-input getMore_u" readonly>
       		<i class="layui-icon layui-icon-more getMore_u" style="position: absolute;right: 35px;top: 9px;"></i>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">指定角色：</label>
        <div class="layui-input-block">
        	<input type="text" name="exceptForRole" id="exceptForRole" th:value="${buttonState?.exceptForRole}" autocomplete="off" placeholder="请选择" class="layui-input getMore_r" readonly>
       		<i class="layui-icon layui-icon-more getMore_r" style="position: absolute;right: 35px;top: 9px;"></i>
        </div>
    </div>
    <div class="layui-form-item layui-hide">
        <input type="button" lay-submit="" lay-filter="btn_save" id="btn_save" value="保存">
    </div>
</form>
<th:block th:include="include :: footer" />
<script th:inline="javascript">
    /*<![CDATA[*/
    var prefix = ctx + "system/button",
    	prefix2 = ctx + "base/company",
		fields = [[${fields}]];
    /*]]>*/
</script>
<script>
var $,layer,form;
layui.use(['form','layer','jquery'], function () {
    $ = layui.$,layer = layui.layer,form = layui.form;
    $.each(fields,function(i,v){
    	if(v.fieldFrontRequired){//如果字段是必填字段，则加上红*并添加必填验证
    		$("#"+v.fields).parent().prev().html('<font class="f_red">*</font>'+v.fieldName+'：');
    		$("#"+v.fields).attr('lay-verify','required');
    	}
    })
});
//功能选择
function getmt(field){
	$.modal.open("功能选择", "/system/dictionaryformodule/select", 650, 510, function(index){
        var res = window["layui-layer-iframe" + index].callbackdata();
        if(res=="none"){
        	layer.msg("请选择！");
        }else{
            $("#"+field).val(res.moduleTable);
            layer.close(index); 
        }
    });
}
//用户选择
$('.getMore_u').on('click', function () {
	var userlist=$('#exceptForUser').val().replace(/\[|]/g,'');
	console.log(userlist);
	$.modal.open('指定用户选择','/system/user/userselect?pagetype=checkbox&selectedUser='+userlist,'925','465',function(index){
        var res = window["layui-layer-iframe" + index].callbackdata();
       	userlist='';
       	$.each(res,function(i,v){
       		userlist+='[' + res[i]['userId'] + '],';
       	})
       	userlist=userlist.substring(0,userlist.length-1);
       	$('#exceptForUser').val(userlist);
       	layer.close(index);
    });
});
//角色选择
$('.getMore_r').on('click', function () {
	var rolelist=$('#exceptForRole').val().replace(/\[|]/g,'');
	$.modal.open('指定角色选择','/system/role/select?pagetype=checkbox','925','500',function(index){
        var res = window["layui-layer-iframe" + index].callbackdata();
        if(res=='none'){
        	$('#exceptForRole').val('');
        	layer.close(index);
        }else{
        	rolelist='';
        	$.each(res,function(i,v){
        		rolelist+='[' + res[i]['guid'] + '],';
        	});
        	rolelist=rolelist.substring(0,rolelist.length-1);
        	$('#exceptForRole').val(rolelist);
        	layer.close(index);
        }
    });
});
//提交调用的方法
function submitHandler() {
	if($('#guid').val()){//通过判断guid是否存在来判断是新增还是保存
		if ($.validate.form()) {
            $.operate.save(prefix + "/editpost", {'buttonStateItems':JSON.stringify([$.common.formToJSON('form-button-add')])});
        }
	}else{
		if ($.validate.form()) {
			$.operate.save(prefix + "/addpost", {'buttonStateItems':JSON.stringify([$.common.formToJSON('form-button-add')])});
		}
	}
}
</script>
</body>
</html>
